package gortepfeil;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class MainFrame extends JFrame
{	
    private JPanel map;
    private MenuBar menu;
    private JPanel layer;
	private JSplitPane splitPane;
    private StatusBar statusbar;
	
    public MainFrame() 
    {
    	super("GIS4Ships");
		setPreferredSize(new Dimension(800, 600));
	    setLocation(100,100);
	    
	    splitPane = new JSplitPane();
	    splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
	     
	    menu = new MenuBar(this);
	    layer = new LayerTree();
	    map = new MapFrame();
	    statusbar = new StatusBar();
	    
	    splitPane.setLeftComponent(layer);
	    splitPane.setRightComponent(map);
		this.setJMenuBar(menu);

		add(statusbar,BorderLayout.SOUTH);
		add(splitPane,BorderLayout.CENTER);
	    pack();
	    setVisible(true);
	}
    
    /*
	 * Method for switching on and off the Statusbar.
	 */
	public void switchStatusbar()
	{
		if (statusbar.isValid()) 
		{
			remove(statusbar);
		} 
		else 
		{
			add(statusbar,BorderLayout.SOUTH);
		}
		
	    pack();
	    setVisible(true);
	}
	
	public void openFile()
	{
		// TODO Auto-generated method stub
		JFileChooser fc = new JFileChooser();
		// show only directories
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	    fc.setDialogTitle("Choose a file to open");
	    fc.showOpenDialog(null);
	}

}
